package com.hrp.hrpdao;

import com.hrp.domain.Jxkhzb;
import com.hrp.domain.Jxzblb;
import com.hrp.domain.Menus;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/8/9 0009.
 */
@Mapper
public interface JxkhzbDao {

    @Select("<script>"
            + "select * from JX_KHZBK where zblb in "
            + "<foreach item='item' index='index' collection='strList' open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<Jxkhzb> getKhzbListByZblb(@Param("strList") List<Integer> strList);

    @Select(" select  id,name from JX_ZBLBK ")
    List<Jxzblb> getAllZblb();

    @Select(" select  * from JX_KHZBK where zbmc=#{zbmc}")
    Jxkhzb getZblistByName(@Param("zbmc") String zbmc);


    @Select("select a.id,a.zbdm,a.zbmc,a.cloumName,a.tybz,a.sjly,b.value,a.zblb,ISNULL(b.zbdm,-1) isChecked from ( select * from JX_KHZBK where zblb in (1,2) ) a inner join ( select * from JX_KS_ZB_MAP where jxksdm=#{jxksdm} and zqid=#{zqid} ) b on a.zbdm = b.zbdm")
    List<Jxkhzb> getZbListByZqidAndJxksdm(@Param("jxksdm") String jxksdm,@Param("zqid") Integer zqid);

    @Select("update JX_KS_ZB_MAP set value=#{value} where jxksdm=#{jxksdm} and zbdm=#{zbdm} and zqid=#{zqid}")
    void saveZbValueByJxksdmAndZqidAndZbid(@Param("value") Double value,@Param("jxksdm") String jxksdm,@Param("zbdm") String zbdm,@Param("zqid") Integer zqid);

    @Select("select 'ZB'+convert(varchar(12),(MAX(id)+1)) zbdm from JX_KHZBK ")
    String getMaxZbid();

    @Select("  insert into JX_KHZBK([zbdm],[zbmc],[cloumName],[tybz],[sjly],[value],[zblb],[khkslb]) values(#{zbdm},#{zbmc},#{cloumName},#{tybz},#{sjly},#{value},#{zblb},#{khkslb}) ")
    void saveKhzbData(Jxkhzb jxkhzb);

    @Select("  select * from JX_KHZBK where id=#{id} ")
    Jxkhzb getJxkhzbById(Integer id);

    @Select(" update JX_KHZBK set zbdm=#{zbdm},zbmc=#{zbmc},cloumName=#{cloumName},tybz=#{tybz},sjly=#{sjly},value=#{value},zblb=#{zblb},khkslb=#{khkslb} where id=#{id} ")
    void updateJxkhzb(Jxkhzb jxkhzb);
}
